package com.sinry.middleware.messages.config;

import com.sinry.message.enums.RabbitQueue;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author linxinlei
 * @project sinry-cloud
 * @description RabbitMQ配置
 * @date 2022/8/7
 **/
@Configuration
public class RabbitSwaggerConfig {

    /**
     * 是否持久化交换机
     */
    Boolean durable = true;
    /**
     * 自动删除（不再被使用时）
     */
    Boolean autoDelete = false;

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(RabbitQueue.SWAGGER_REPORT.getExchange(), durable, autoDelete);
    }

    @Bean
    public Queue queue() {
        return new Queue(RabbitQueue.SWAGGER_REPORT.getQueue(), durable);
    }

    @Bean
    public Binding binding(TopicExchange topicExchange, Queue queue) {
        return BindingBuilder.bind(queue).to(topicExchange).with(RabbitQueue.SWAGGER_REPORT.getQueue());
    }
}
